package org.icdio.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.icdio.dao.RegisterDao;
import org.icdio.entity.User;
import org.icdio.utils.DBUtils;

public class RegisterDaoImpl implements RegisterDao{

	Connection conn;
	
	@Override
	public boolean register(User user) throws Exception {
		conn = DBUtils.open();
		String sql = "Insert into User (userName,password) Values (?,?)";
		PreparedStatement preparedStatement = conn.prepareStatement(sql);
		
		preparedStatement.setString(1, user.getUserName());
		
		preparedStatement.setString(2, user.getPassword());

		if(preparedStatement.executeUpdate() != 0) {
			if(null != conn) {
				conn.close();				
			}
			return true;
		}
		if(null != conn) {
			conn.close();				
		}
		return false;
	}

}
